<template>
    <el-dialog
            :title="!dataForm.outcomeId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="成果ID" prop="outcomeId">
                        <el-input v-model.number="dataForm.outcomeId" placeholder="成果ID"></el-input>
                </el-form-item>
                <el-form-item label="项目ID" prop="projectId">
                        <el-input v-model.number="dataForm.projectId" placeholder="项目ID"></el-input>
                </el-form-item>
                <el-form-item label="成果名称" prop="outcomeName">
                        <el-input v-model="dataForm.outcomeName" placeholder="成果名称"></el-input>
                </el-form-item>
                <el-form-item label="提交者" prop="submitter">
                        <el-input v-model="dataForm.submitter" placeholder="提交者"></el-input>
                </el-form-item>
                <el-form-item label="提交时间" prop="submitDate">
                        <el-date-picker
                                v-model="dataForm.submitDate"
                                type="datetime"
                                placeholder="提交时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="审核状态" prop="reviewStatus">
                        <el-input v-model="dataForm.reviewStatus" placeholder="审核状态"></el-input>
                </el-form-item>
                <el-form-item label="审核人" prop="reviewer">
                        <el-input v-model="dataForm.reviewer" placeholder="审核人"></el-input>
                </el-form-item>
                <el-form-item label="审核时间" prop="reviewDate">
                        <el-date-picker
                                v-model="dataForm.reviewDate"
                                type="datetime"
                                placeholder="审核时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="成果描述" prop="outcomeDescription">
                        <el-input v-model="dataForm.outcomeDescription" placeholder="成果描述"></el-input>
                </el-form-item>
                <el-form-item label="成果文件路径" prop="outcomeFilePath">
                        <el-input v-model="dataForm.outcomeFilePath" placeholder="成果文件路径"></el-input>
                </el-form-item>
                <el-form-item label="审核意见" prop="reviewOpinion">
                        <el-input v-model="dataForm.reviewOpinion" placeholder="审核意见"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            outcomeId: null,
            projectId: null,
            outcomeName: null,
            submitter: null,
            submitDate: null,
            reviewStatus: null,
            reviewer: null,
            reviewDate: null,
            outcomeDescription: null,
            outcomeFilePath: null,
            reviewOpinion: null
          },
          dataRule: {
            outcomeId: [
                        { required: true, message: '成果ID不能为空', trigger: 'blur' }
            ],
            projectId: [
                        { required: true, message: '项目ID不能为空', trigger: 'blur' }
            ],
            outcomeName: [
                        { required: true, message: '成果名称不能为空', trigger: 'blur' }
            ],
            submitter: [
                        { required: true, message: '提交者不能为空', trigger: 'blur' }
            ],
            submitDate: [
                        { required: true, message: '提交时间不能为空', trigger: 'blur' }
            ],
            reviewStatus: [
                        { required: true, message: '审核状态不能为空', trigger: 'blur' }
            ],
            reviewer: [
                        { required: true, message: '审核人不能为空', trigger: 'blur' }
            ],
            reviewDate: [
                        { required: true, message: '审核时间不能为空', trigger: 'blur' }
            ],
            outcomeDescription: [
                        { required: true, message: '成果描述不能为空', trigger: 'blur' }
            ],
            outcomeFilePath: [
                        { required: true, message: '成果文件路径不能为空', trigger: 'blur' }
            ],
            reviewOpinion: [
                        { required: true, message: '审核意见不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.outcomeId = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.outcomeId = id || 0
            if (this.dataForm.outcomeId) {
              this.$http({
                url: this.$http.adornUrl(`/app/project_outcome/info/${this.dataForm.outcomeId}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appprojectoutcome
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/project_outcome/${!this.dataForm.outcomeId ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>